home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / torsocks < prev    next >
Encoding:
Text File  |  2012-03-03  |  5.3 KB  |  154 lines

  1. #!/bin/sh
  2. # ***************************************************************************
  3. # *                                                                         *
  4. # *                                                                         *
  5. # *   Copyright (C) 2008 by Robert Hogan                                    *
  6. # *   robert@roberthogan.net                                                *
  7. # *                                                                         *
  8. # *   This program is free software; you can redistribute it and/or modify  *
  9. # *   it under the terms of the GNU General Public License as published by  *
  10. # *   the Free Software Foundation; either version 2 of the License, or     *
  11. # *   (at your option) any later version.                                   *
  12. # *                                                                         *
  13. # *   This program is distributed in the hope that it will be useful,       *
  14. # *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  15. # *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  16. # *   GNU General Public License for more details.                          *
  17. # *                                                                         *
  18. # *   You should have received a copy of the GNU General Public License     *
  19. # *   along with this program; if not, write to the                         *
  20. # *   Free Software Foundation, Inc.,                                       *
  21. #*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  22. # ***************************************************************************
  23. # *                                                                         *
  24. # *   This is a modified version of a source file from the Tor project.     *
  25. # *   Original copyright information follows:                               *
  26. # ***************************************************************************
  27. # Wrapper script for use of the torsocks(8) transparent socksification library
  28. #
  29. # There are three forms of usage for this script:
  30. #
  31. # /usr/bin/torsocks program [program arguments...]
  32. #
  33. # This form sets the users LD_PRELOAD environment variable so that torsocks(8)
  34. # will be loaded to socksify the application then executes the specified 
  35. # program (with the provided arguments). The following simple example might 
  36. # be used to telnet to www.foo.org via a torsocks.conf(5) configured socks server:
  37. #
  38. # /usr/bin/torsocks telnet www.foo.org
  39. #
  40. # The second form allows for torsocks(8) to be switched on and off for a
  41. # session (that is, it adds and removes torsocks from the LD_PRELOAD environment
  42. # variable). This form must be _sourced_ into the user's existing session
  43. # (and will only work with bourne shell users):
  44. #
  45. # . /usr/bin/torsocks on
  46. # telnet www.foo.org 
  47. # . /usr/bin/torsocks off
  48. # Or
  49. # source /usr/bin/torsocks on
  50. # telnet www.foo.org
  51. # source /usr/bin/torsocks off
  52. #
  53. # The third form creates a new shell with LD_PRELOAD set and is achieved
  54. # simply by running the script with no arguments 
  55. # /usr/bin/torsocks
  56. #
  57. # When finished the user can simply terminate the shell with 'exit'
  58. # This script is originally from the debian torsocks package by
  59. # Tamas Szerb <toma@rulez.org>
  60. # Modified by Robert Hogan <robert@roberthogan.net> April 16th 2006
  61.  
  62. not_found () {
  63.     echo "ERROR: $1 cannot be found in PATH." >&2
  64.     exit 1
  65. }
  66.  
  67. set_id () {
  68.     echo "ERROR: $1 is set${2}id. torsocks will not work on a set${2}id executable." >&2
  69.     exit 1
  70. }
  71.  
  72. if [ $# = 0 ] ; then
  73.    echo "$0: insufficient arguments"
  74.    exit
  75. fi
  76.  
  77. LIBDIR="/usr/lib/torsocks"
  78. LIB_NAME="libtorsocks"
  79. SHLIB_EXT="so"
  80. SHLIB="${LIBDIR}/${LIB_NAME}.${SHLIB_EXT}"
  81.  
  82. # Ensure libtorsocks exists,
  83. if [ ! -f $SHLIB ]; then
  84.    echo "$0: $SHLIB does not exist! Try re-installing torsocks."
  85.    exit
  86. fi
  87.  
  88. case "$1" in
  89.   on)
  90.     if [ -z "$LD_PRELOAD" ]
  91.       then
  92.         export LD_PRELOAD="${SHLIB}"
  93.       else
  94.         echo $LD_PRELOAD | grep -q "${SHLIB}" || \
  95.         export LD_PRELOAD="${SHLIB} $LD_PRELOAD"
  96.     fi
  97.     # FIXME: This env variable is only meaningful on Mac OSX, so it would be better
  98.     #        not to set it at all on other platforms.
  99.     export DYLD_FORCE_FLAT_NAMESPACE=1
  100.   ;;
  101.   off)
  102.     #replace '/' with '\/' in /usr
  103.     # escprefix=`echo '/usr' |sed 's/\\//\\\\\//g'`
  104.     # export LD_PRELOAD=`echo -n $LD_PRELOAD | sed "s/$escprefix\/lib\/torsocks\/libtorsocks.so \?//"`
  105.     export LD_PRELOAD=`echo -n $LD_PRELOAD | sed "s#/usr/lib/torsocks/libtorsocks\.so *##"`
  106.     if [ -z "$LD_PRELOAD" ]
  107.       then
  108.         unset LD_PRELOAD
  109.         # FIXME: This env variable is only meaningful on Mac OSX, so it would be better
  110.         #        not to set it at all on other platforms.
  111.         unset DYLD_FORCE_FLAT_NAMESPACE=1
  112.     fi
  113.   ;;
  114.   show|sh)
  115.     echo "LD_PRELOAD=\"$LD_PRELOAD\""
  116.   ;;
  117.   -h|-?)
  118.       echo "$0: Please see torsocks(1) or read comment at top of $0"
  119.    ;;
  120.   *)
  121.     if [ -z "$LD_PRELOAD" ]
  122.     then
  123.       export LD_PRELOAD="${SHLIB}"
  124.     else
  125.       echo $LD_PRELOAD | grep -q "${SHLIB}" || \
  126.       export LD_PRELOAD="${SHLIB} $LD_PRELOAD"
  127.     fi
  128.     export DYLD_FORCE_FLAT_NAMESPACE=1
  129.  
  130.     if [ $# = 0 ]
  131.     then
  132.       ${SHELL:-/bin/sh}
  133.     fi
  134.  
  135.     if [ $# -gt 0 ]
  136.     then
  137.       if ! which "$1" >/dev/null 2>&1; then
  138.           not_found $1
  139.       elif [ -u `which "$1"` ]; then
  140.           set_id $1 u
  141.       elif [ -g `which "$1"` ]; then
  142.           set_id $1 g
  143.       fi
  144.       exec "$@"
  145.     fi
  146.   ;;
  147. esac
  148.  
  149. #EOF
  150.